﻿'************************************************************************************'
'* Copyright (c) 2009, Patrick Driscoll All rights reserved.                        *'
'*                                                                                  *'
'* Redistribution and use in source and binary forms, with or without               *'
'* modification, are permitted provided that the following conditions are met:      *'
'*                                                                                  *'
'* Redistributions of source code must retain the above copyright notice, this      *'
'* list of conditions and the following disclaimer. Redistributions in binary       *'
'* form must reproduce the above copyright notice, this list of conditions and      *'
'* the following disclaimer in the documentation and/or other materials             *'
'* provided with the distribution. Neither the name of the DriscollArt Software nor *'
'* the names of its contributors may be used to endorse or promote products         *'
'* derived from this software without specific prior written permission.            *'
'*                                                                                  *'
'* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"      *'
'* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE        *'
'* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE       *'
'* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR      *'
'* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL           *'
'* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR       *'
'* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER       *'
'* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT               *'
'* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY        *'
'* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH      *'
'* DAMAGE.                                                                          *'
'************************************************************************************'

Imports Microsoft.VisualBasic
Imports System
Imports System.Text
Imports System.CodeDom.Compiler
Imports System.Reflection
Imports System.IO
Imports System.Diagnostics
Imports System.Web

''' <summary>
''' Interface for EvalProvider
''' </summary>
Public MustInherit Class EvalProvider

	Protected evalClassBegin As String = _
	  "Imports System" & vbCrLf & _
	  "Imports System.Xml" & vbCrLf & _
	  "Imports System.Data" & vbCrLf & _
	  "Imports System.IO" & vbCrLf & _
	  "Imports Microsoft.VisualBasic" & vbCrLf & _
	  "Imports System.Text" & vbCrLf & _
	  "Imports System.Web" & vbCrLf & _
	  "Namespace dValuate" & vbCrLf & _
	  "Class EvalRunTime " & vbCrLf & _
	  "Public Function GetDesktopModulesDirectoryName(ByVal DNNProperties As Collection, ByVal DatabaseProperties As DataTable) As String" & vbCrLf & _
	  " Dim objCodePath As New System.IO.DirectoryInfo(DNNProperties.Item(""RootDNNPath"") & ""\DesktopModules\"" & DNNProperties.Item(""Company"").Replace("" "", """") & ""."" & DNNProperties.Item(""ClassName""))" & vbCrLf & _
	  " If objCodePath.Exists = False Then" & vbCrLf & _
	  " objCodePath.Create()" & vbCrLf & _
	  " End If" & vbCrLf & _
	  " Return objCodePath.FullName" & vbCrLf & _
	  "End Function" & vbCrLf & _
	  "Public Function GetAppCodeDirectoryName(ByVal DNNProperties As Collection, ByVal DatabaseProperties As DataTable) As String" & vbCrLf & _
	  " Dim objCodePath As New System.IO.DirectoryInfo(DNNProperties.Item(""RootDNNPath"") & ""\App_Code\"" & DNNProperties.Item(""NameSpace"") & ""."" & DNNProperties.Item(""ClassName""))" & vbCrLf & _
	  " If objCodePath.Exists = False Then" & vbCrLf & _
	  " objCodePath.Create()" & vbCrLf & _
	  " End If" & vbCrLf & _
	  " Return objCodePath.FullName" & vbCrLf & _
	  "End Function" & vbCrLf & _
	  "Public Function GetAppLocalResourcesDirectoryName(ByVal DNNProperties As Collection, ByVal DatabaseProperties As DataTable) As String" & vbCrLf & _
	  " Dim objCodePath As New System.IO.DirectoryInfo(DNNProperties.Item(""RootDNNPath"").ToString & ""\DesktopModules\"" & DNNProperties.Item(""Company"").ToString.Replace("" "", """") & ""."" & DNNProperties.Item(""ClassName"").ToString & ""\App_LocalResources"")" & vbCrLf & _
	  " If objCodePath.Exists = False Then" & vbCrLf & _
	  " objCodePath.Create()" & vbCrLf & _
	  " End If" & vbCrLf & _
	  " Return objCodePath.FullName" & vbCrLf & _
	  "End Function" & vbCrLf & _
	  "Public Sub SaveCodeFile(Optional ByVal DNNProperties As Collection = Nothing, Optional ByVal DatabaseProperties As DataTable = Nothing)" & vbCrLf & _
	  " Dim strFileName As String = GetFileName(DNNProperties, DatabaseProperties)" & vbCrLf & _
	  " Dim objStringWriter As New System.IO.StreamWriter(New System.IO.FileStream(strFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write))" & vbCrLf & _
	  " objStringWriter.Write(GenerateCodeString(DNNProperties, DatabaseProperties))" & vbCrLf & _
	  " objStringWriter.Close()" & vbCrLf & _
	  "End Sub"

	Protected evalClassEnd As String = "End Class " & vbCrLf & _
  "End Namespace" & vbCrLf

	Private m_oCompilerErrors As CompilerErrorCollection

	Public Sub New()
		MyBase.New()
		m_oCompilerErrors = New CompilerErrorCollection
	End Sub

	Public Property CompilerErrors() As CompilerErrorCollection
		Get
			Return m_oCompilerErrors
		End Get
		Set(ByVal Value As CompilerErrorCollection)
			m_oCompilerErrors = Value
		End Set
	End Property

	Public MustOverride Function GenerateDNNCode(ByVal vbCode As String, ByVal DNNProperties As Collection, ByVal DatabaseProperties As DataTable) As String
	Public MustOverride Sub SaveDNNCode(ByVal vbCode As String, ByVal DNNProperties As Collection, ByVal DatabaseProperties As DataTable)

End Class
